<?php
namespace data\service;

use data\model\ContentModel;

class ContentService extends BaseService {

    private $contentModel = null;
    //private $bgColor = ['#D2691E','#FF8247','#008B8B','#6495ED'];
    private $bgColor = ['#ffffff','#ffffff','#ffffff','#ffffff'];

    public function __construct() {
        parent::__construct();
        $this->contentModel = new ContentModel();
    }

    public function getContent( $page , $pageSize , $where , $order = "",$fields = "*"){
        $contentLists = $this->contentModel->pageQuery( $page , $pageSize , $where , $order ,$fields );
        $retData = [];
        if(!empty($contentLists['data'])){
            foreach($contentLists['data'] as $ck => $cv){
                $retData[$ck] = [
                    'id' => $cv['id'],
                    'ptype' => $cv['ptype'],
                    'type' => $cv['type'],
                    'desc' => $cv['desc'],
                    'xclass' => $this->bgColor[$cv['id'] % 4],
                ];
            }
            return $retData;
        }
        return [];
    }


    public function contentDetail( $contentId = 0 ,$fields = "*" ){
        $contentDetail = $this->contentModel->getInfo( ['id' => $contentId] ,$fields) ;

        if(!empty($contentDetail)){
            return $contentDetail;
        }
        return [];
    }


}
